package com.zx.shop.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.*;

import com.zx.shop.bean.Goods;
import com.zx.shop.dao.IGoods;
import com.zx.shop.dao.impl.GoodsDaoImpl;

public class AddGoodsFrame extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public AddGoodsFrame() {
		this.setTitle("商品分类");
		this.setBounds(120, 120, 300, 200);
		
		JPanel p1 = new JPanel();
		JLabel l1 = new JLabel("商品名:");
		JLabel l2 = new JLabel("商品价格:");
		JLabel l3 = new JLabel("商品编号:");
		
		JTextField tf1 = new JTextField(20);
		JTextField tf2=new JTextField(20);
		JTextField tf3=new JTextField(20);
		
		
		JButton btn1 = new JButton("添加");
		
		p1.add(l1);
		p1.add(l2);
		p1.add(l3);
		p1.add(tf1);
		p1.add(tf2);
		p1.add(tf3);
		p1.add(btn1);
		
		this.add(p1);
		
		
		btn1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				String gname = tf1.getText();
				String gprice=tf2.getText();
				String cid=tf3.getText();
				//ICategoryDao dao = new CategoryDaoImpl();
				IGoods dao=new GoodsDaoImpl();
				try {
					
					dao.insert(new Goods(0,gname,gprice , cid));
					JOptionPane.showMessageDialog(null,"添加成功");
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
	}

}
